Developer --> Technical Publications
PATHJava Developer Documentation > Mac OS Runtime for Java > JManager > Programming With JManager


Update, Activate, and Resume Events

If the application receives an update event, it must update the currently active window. If the window corresponds to a frame, you must pass the update event to the frame using the JMFrameUpdate function JMFrameUpdate. The AWT context can then update the actual window using a callback. Listing 1-13 shows an example of an update function.

Listing 1-13 Handling a frame update event

static void handleUpdate(WindowPtr win)
{
    JMFrameRef frame;
    BeginUpdate(win);
    SetPort(win);
    frame = (JMFrameRef) GetWRefCon(win);
    if (frame)
        JMFrameUpdate(frame, win->visRgn);
    else
        EraseRgn(win->visRgn);
    EndUpdate(win);
}

If an activate event occurs, then a window was made active (that is, brought to the front), and if that window is associated with a frame, you must activate the frame using the JMFrameActivate function JMFrameActivate. This action gives the frame the opportunity to highlight title bars, scroll bars, and so on. Activating a frame also installs the menu bar associated with the frame. Listing 1-14 gives an example of activating a frame.

Listing 1-14 Sending an activate event to a frame

static void handleActivate(Boolean active, WindowPtr window)
{
    JMFrameRef frame = (JMFrameRef) GetWRefCon(window);
    if (frame)
        JMFrameActivate(frame, active);
}

Note

The JMFrameActivate function can either activate or deactivate a frame, depending on the Boolean value passed to it (the value of active in this example).

Suspend and resume events can also occur when a window is activated or deactivated. When the user switches from one application to another, the newly selected application is sent a resume event, and the previously active one is sent a suspend event. This event affects all the applets embedded within an application, so you must call the JMFrameResume function JMFrameResume to suspend or resume all the existing frames.

Listing 1-15 shows how to send a resume event to all the frames associated with a client application.

Listing 1-15 Sending a resume event to frames

static void handleResume(Boolean resume)
{
    WindowPtr win = FrontWindow();
    while (win) {
        JMFrameRef frame = (JMFrameRef) GetWRefCon(win);
        if (frame)
            JMFrameResume(frame, resume);
        win = (WindowPtr) ((WindowPeek) win)->nextWindow;
    }
}

Note

The JMFrameResume function can either suspend or resume a frame, depending on the Boolean value passed to it (the value of resume in this example).

This example cycles through all the visible windows used by the application and sends the event to those associated with frames. However, this example only works if every frame is associated with a window. If this is not the case, you must use some other method to send the resume event.


© 1998 Apple Computer, Inc. — (Last Updated 3 Dec 98)

Previous | Back Up One Level | Next |